package com.huang.controller;

import com.huang.pojo.User;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@RestController
public class AjaxController {
    @RequestMapping("/t1")
    public String test() {
        return "test";
    }

    @RequestMapping("/a1")
    public void ajax1(String name, HttpServletResponse response) throws IOException {
        if ("admin".equals(name)) {
            response.getWriter().print("true");
        } else {
            response.getWriter().print("false");
        }
    }

    @RequestMapping("/a2")
    public List<User> a2() {
        List<User> list = new ArrayList<>();
        //添加数据
        list.add(new User("黄小小", 18, "女"));
        list.add(new User("黄大大", 18, "男"));
        return list;
    }

    @RequestMapping("/a3")
    public String a3(String name) {
        String msg = "";
        if (name != null) {
            if ("admin".equals(name)){
                msg="ok";
            }else {
                msg="false";
            }
        }
        return msg;
    }
}
